<?php
class Yourprofile_model extends Model{

    var $username   = '';
    var $firstname 	= '';
    var $lastname  	= '';
    var $phone  	= '';
    var $email  	= '';
	var $errmsg    	= '';

    function Yourprofile_model(){
        parent::Model();       
    }
    function loadprofile(){ 		
    	$query = $this->db->get_where('users',array('username'=>get_cookie('username_admin')));
    	$res = $query->row();
    	$this->username = $res->username;
    	$this->firstname = $res->firstname;
    	$this->lastname = $res->lastname;
    	$this->phone = $res->phone;
    	$this->email = $res->email;
    }
    function saveprofile(){
    	if(FALSE!==$this->input->post('hidden_status')){
    		$this->username = get_cookie('username_admin');
    		$this->firstname = $this->input->post('txt_firstname');  
    		$this->lastname = $this->input->post('txt_lastname');  
    		$this->phone = $this->input->post('txt_phone');  
    		$this->email = $this->input->post('txt_email');    	
			$this->db->where('username',$this->username);
			$this->db->update('users',array('firstname'=>$this->firstname,'lastname'=>$this->lastname,'phone'=>$this->phone,'email'=>$this->email));
    	}
    }
	function changepassword(){
    	if(FALSE!==$this->input->post('hidden_status')){
    		$username = get_cookie('username_admin');
    		$currpwd = $this->input->post('txt_currentpwd');
    		$newpwd = $this->input->post('txt_newpwd');
    		$query = $this->db->get_where('users',array('username'=>$username,'password'=>md5($currpwd)));
    		if($query->num_rows()){
    			$this->db->where('username',$username);
    			$this->db->update('users',array('password'=>md5($newpwd)));
    			return true;
    		}
    		else $this->errmsg = lang('yourprofile_msg_invalidcurrpwd');
    	}
    	return false;
    }
}

/* End of file yourprofile_model.php */
/* Location: ./system/application/admin/controllers/yourprofile_model.php */